package com.company.nuwa.mybatis.generator.plugins;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.io.File;
import java.util.Date;
import java.util.StringTokenizer;

/**
 * <p></p>
 *
 * @author lili
 * @version 1.0: ApiExtPluginUtils
 * @date 2023/9/18 09:35
 */
public class ApiExtPluginUtils {

    public static boolean isExistExtFile(String targetProject, String targetPackage, String fileName) {

        File project = new File(targetProject);
        if (!project.isDirectory()) {
            return true;
        }

        StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(targetPackage, ".");
        while (st.hasMoreTokens()) {
            sb.append(st.nextToken());
            sb.append(File.separatorChar);
        }

        File directory = new File(project, sb.toString());
        if (!directory.isDirectory()) {
            boolean rc = directory.mkdirs();
            if (!rc) {
                return true;
            }
        }

        File testFile = new File(directory, fileName);
        return testFile.exists();
    }


    public static String getDateString() {
        return DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
    }




    public static String transformPackagePaths(String originalPath, String domainReplacement, String mapperReplacement) {
        if (originalPath == null || domainReplacement == null || mapperReplacement == null) {
            throw new IllegalArgumentException("Input strings cannot be null");
        }
      //  return originalPath.replace(".domain", domainReplacement).replace(".mapper", mapperReplacement);
        return originalPath.replace(".domain", domainReplacement).replace(".mapper", "")+mapperReplacement;

    }
}
